package system.base;

import framework.core.*;

public class ProductOutCategorySearchEvent extends SearchEvent {
	
    private ProductOutCategory poc;
    

    public ProductOutCategory getPoc() {
		return poc;
	}


	public void setPoc(ProductOutCategory poc) {
		this.poc = poc;
	}


	public Conditions toConditions() throws Exception {
        Conditions c = super.toConditions();
       int i=0;
       String sql=" status=1 ";
       String apendSql=" and product_id in ( select id from t_product where  ";
       if(!poc.getOutCategory().equals("")){
    	   sql+=" and  out_category = '"+poc.getOutCategory()+"'";
    	
       }
       if(!poc.getProductName().equals("")){
    	   apendSql+=" name like '%"+poc.getProductName()+"%'";
    	   i++;
       }
       
       if(!poc.getSpec().equals("")){
    	  
    	   if(i>0){
    		   apendSql+=" and spec like '%"+poc.getSpec()+"%'"; 
    	   }else{
    		   apendSql+="  spec like '%"+poc.getSpec()+"%'"; 
    	   }
    	   i++;
       }
       
       if(!poc.getModel().equals("")){
    	   
    	   if(i>0){
    		   apendSql+=" and model like '%"+poc.getModel()+"%'";
    	   }else{
    		   apendSql+=" model like '%"+poc.getModel()+"%'";
    	   }
    	   i++;
       }
       
        if(!poc.getProductCode().equals("")){
    	   
    	   if(i>0){
    		   apendSql+=" and concentricity_code like '%"+poc.getProductCode()+"%'";
    	   }else{
    		   apendSql+=" concentricity_code like '%"+poc.getProductCode()+"%'";
    	   }
    	   i++;
       }
       if(i>0){
    	   sql+=apendSql+") ";
       }
      c.add(sql);
      return c;
    }
}
